package cn.demomaster.quickdb.mapper;

import android.database.Cursor;

import java.util.ArrayList;
import java.util.List;

import cn.demomaster.quickdb.model.ColumnInfo;

public abstract class CursorMapper<T> {
    public String tableName;
    List<ColumnInfo> columnInfoList;
    public List<ColumnInfo> getColumnInfoList() {
        return columnInfoList;
    }
    public abstract T createEntity(Cursor cursor);

    public List<T> mapToList(Cursor cursor) {
        List<T> entities = new ArrayList<>();
        if (cursor != null && cursor.moveToFirst()) {
            do {
                entities.add(createEntity(cursor));
            } while (cursor.moveToNext());
        }
        if (cursor != null) {
            cursor.close();
        }
        return entities;
    }
    public T mapToEntry(Cursor cursor) {
        return createEntity(cursor);
    }

    public abstract String getTableName();
    public abstract String getDataBaseName();
    public abstract String generateInsertSql(T obj);
    public abstract String generateCreateTableSql();
    public abstract String generateInsertSql(List<T> models,Class<T> clazz);
    public abstract String generateModifySql(List<T> models,Class<T> clazz);
    public abstract Object getFieldValue(T obj,String fieldName);
}
